package com.taoz.rpc.core.server.tcp;

import com.taoz.rpc.core.server.Server;
import io.vertx.core.Vertx;
import io.vertx.core.net.NetServer;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class VertxTcpServer implements Server {

    @Override
    public void start(int port) {
        NetServer server = Vertx.vertx().createNetServer();

        server.connectHandler(new VertxTcpRequestHandler());

        server.listen(port, result -> {
            if (result.succeeded()) {
                log.info("Server is now listening at port: " + port);
            } else {
                log.info("Fail to start server: " + result.cause());
            }
        });
    }
}
